package org.zk.service.impl;

import org.zk.dao.GoodsMapper;
import org.zk.dao.OrdersMapper;
import org.zk.entity.Goods;
import org.zk.entity.Orders;
import org.zk.entity.OrdersExt;
import org.zk.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class OrdersServiceImpl implements OrdersService {

    @Autowired
    private OrdersMapper ordersMapper;
    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public List<OrdersExt> getOrderses(Integer uid) {

        List<OrdersExt> ordersExts = new ArrayList<>();

        List<Orders> orderses = ordersMapper.selectOrdersesByUid(uid);
        if(orderses!=null){

            for(Orders order:orderses){
                OrdersExt ordersExts1 = new OrdersExt(order);

                Goods goods = goodsMapper.selectGoodsByGidWithoutStatus(order.getGoodsId());

                if(goods != null){
                    ordersExts1.setGoodsName(goods.getName());
                }
                ordersExts.add(ordersExts1);
            }

        }

        return ordersExts;
    }
}
